package com.tt.fashionWebSite.dao.jpa;

import com.tt.fashionWebSite.dao.SanPhamDao;
import com.tt.fashionWebSite.domain.DatHang;
import com.tt.fashionWebSite.domain.HoaDon;
import com.tt.fashionWebSite.domain.SanPham;
import com.tt.fashionWebSite.dto.SanPhamDto;
import org.springframework.stereotype.Repository;

import javax.persistence.Query;
import java.util.List;

@Repository("sanPham")
public class SanPhamJpaDao extends GenericJpaDao<SanPham,String> implements SanPhamDao {
    public SanPhamJpaDao(){
        super(SanPham.class);
    }

    @Override
    public List<SanPham> getAllProduct(){
        return getEntityManager().createNamedQuery(SanPham.GET_PRODUCT_ALL, SanPham.class).getResultList();
    }

    @Override
    public List<SanPham> getProductWidthCategoryM(String maLoaiDMSP){
        return getEntityManager().createNamedQuery(SanPham.GET_PRODUCT_ALL_WIDTH_CATEGORYM, SanPham.class)
                .setParameter("maLoaiDMSP", maLoaiDMSP)
                .getResultList();
    }

    @Override
    public List<SanPham> getProductWidthCategoryF(String maLoaiDMSP){
        return getEntityManager().createNamedQuery(SanPham.GET_PRODUCT_ALL_WIDTH_CATEGORYF, SanPham.class)
                .setParameter("maLoaiDMSP", maLoaiDMSP)
                .getResultList();
    }

    @Override
    public void deleteProductCommon(String maSP) {
        Query q1 = getEntityManager().createQuery("DELETE FROM SanPham c WHERE c.maSP = :maSP ");
        q1.setParameter("maSP", maSP);
        q1.executeUpdate();
    }
}
